//package com.wll.combat.微信小程序公众号;
//
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.github.pagehelper.util.StringUtil;
//import com.yeejoin.precontrol.common.dto.small.WxMssDto;
//import com.yeejoin.precontrol.common.entity.Person;
//import com.yeejoin.precontrol.common.entity.WechatRelation;
//import com.yeejoin.precontrol.common.entity.WechatSendMessage;
//import com.yeejoin.precontrol.common.exception.BaseException;
//import com.yeejoin.precontrol.common.service.IPersonService;
//import com.yeejoin.precontrol.common.service.IWechatRelationService;
//import com.yeejoin.precontrol.common.service.IWechatSendMessageService;
//import com.yeejoin.precontrol.common.service.SmallProService;
//import com.yeejoin.precontrol.common.utils.HttpUtils;
//import com.yeejoin.precontrol.common.utils.RedisUtil;
//import com.yeejoin.precontrol.common.vo.ResponeVo;
//import com.yeejoin.precontrol.controller.publics.BaseController;
//import io.micrometer.core.instrument.util.StringUtils;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.http.MediaType;
//import org.springframework.web.bind.annotation.*;
//
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.security.KeyManagementException;
//import java.security.KeyStoreException;
//import java.security.NoSuchAlgorithmException;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.List;
//import java.util.Map;
//
///**
// *  小程序 公众号  通信
// *
// */
//@RestController
//@Api(tags = "小程序控制层")
//@RequestMapping(value = "/small", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//@Slf4j
//public class SmallController extends BaseController {
//
//    /**
//     * 小程序appid
//     */
//    @Value("${smallProgram.appid}")
//    private String appId;
//    /**
//     * 小程序secret
//     */
//    @Value("${smallProgram.secret}")
//    private String secret;
//    /**
//     * 小程序grantType
//     */
//    @Value("${smallProgram.grant_type}")
//    private String grantType;
//    /**
//     * 小程序secret
//     */
//    @Value("${smallProgram.tutorial_id}")
//    private String tutorialId;
//    /**
//     * 公众号appid
//     */
//    @Value("${smallProgram.public.appid}")
//    private String publicAppId;
//    /**
//     * 公众号secret
//     */
//    @Value("${smallProgram.public.secret}")
//    private String publicSecret;
//    /**
//     * 小程序服务类
//     */
//    @Autowired
//    SmallProService smallProService;
//
//    @Autowired
//    IPersonService iPersonService;
//
//    @Autowired
//    private IWechatSendMessageService wechatSendMessageService;
//
//    @Autowired
//    private IWechatRelationService wechatRelationService;
//
//    @Autowired
//    RedisUtil redisUtil;
//
//    /**
//     * 获取code
//     * https://developers.weixin.qq.com/miniprogram/dev/api/open-api/login/wx.login.html
//     * 获取openId
//     * https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html
//     *
//     * @return
//     */
//    @RequestMapping(value = "/getOpenId", method = RequestMethod.GET)
//    @ApiOperation(httpMethod = "GET", value = "通过code换 请求openId链接", notes = "通过code换 请求openId链接")
//    public Object exchangeSmallProMesssage(String code) throws IOException {
//        String url = buildOpenIdUrl(appId, secret, code);
//        ResponeVo responeVo = HttpUtils.get(url);
//        JSONObject jsonObject = JSONObject.parseObject(responeVo.getContent());
//        if (jsonObject != null) {
//            int errcode = jsonObject.getIntValue("errcode");
//            if (errcode == 0) {
//                // session_key 会话秘钥
////                String sessionKey = jsonObject.getString("session_key");
//                String unionid = jsonObject.getString("unionid");
//                String openId = jsonObject.getString("openid");
//                Person person = getPerson();
//                if (person != null && person.getId() != null) {
//                    WechatRelation wechatRelation = wechatRelationService.getOne(new LambdaQueryWrapper<WechatRelation>().eq(WechatRelation::getUnionId, unionid));
//                    if (wechatRelation == null) {
//                        wechatRelation = new WechatRelation();
//                        wechatRelation.setSmallOpenId(openId);
//                        wechatRelation.setUnionId(unionid);
//                        wechatRelation.setPersonId(person.getId());
//                        wechatRelation.setCreateDate(new Date());
//                        wechatRelationService.save(wechatRelation);
//                    } else {
//                        wechatRelation.setPersonId(person.getId());
//                        wechatRelation.setSmallOpenId(openId);
//                        wechatRelationService.updateById(wechatRelation);
//                    }
////                    Person newPerson = new Person();
////                    newPerson.setId(person.getId());
////                    newPerson.setOpenId(openId);
////                    iPersonService.updateById(newPerson);
//                }
//                return openId;
//            } else {
//                throw new BaseException(jsonObject.getString("errmsg"));
//            }
//        } else {
//            throw new BaseException("微信接口调用失败");
//        }
//    }
//
//    @RequestMapping(value = "/getPublicOpenId", method = RequestMethod.GET)
//    @ApiOperation(httpMethod = "GET", value = "通过code换 请求openId链接", notes = "通过code换 请求openId链接")
//    public Object getPublicOpenId() {
//        try {
////            String accessToken = getAccessToken();
//            String accessToken = "47_HCgH5O9PmylM_Ajgo1-_ujZ4lRGZ53IAY7y2yiVj1F87aualC-pBIczyVfEjZ39uFek2T5O8W4UesOtiPZumkEltAdXMWCpFLAlTJnGSpjhzsRv5CWUjEptTHOpjHn_yUXyBNmquKJVPJ0y-STPjABAABX";
////            Object userOpenIdList = getUserOpenIdList("", accessToken);
//            getPublicUnionIdByOpenId(accessToken);
//        } catch (Exception e) {
//            e.getStackTrace();
//            log.info(e.getMessage());
//        }
//        return null;
//    }
//
//    /*
//     * 获取公众号 accesstoken
//     * (non-Javadoc)
//     * @see com.yspro.service.PubUserService#getAccessToken()
//     */
//    public String getAccessToken() throws Exception {
//        String accessToken = "";
//        String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + publicAppId + "&secret=" + publicSecret;
//        ResponeVo responeVo = HttpUtils.post(url, "");
//        JSONObject jsonResult = JSONObject.parseObject(responeVo.getContent());
//        // 成功后 返回参数中没有 errcode
//        if (jsonResult != null) {
//            accessToken = jsonResult.getString("access_token");
//            if (StringUtil.isNotEmpty(accessToken)) {
//                String expires_in = jsonResult.getString("expires_in");
//                Long timeStamp = System.currentTimeMillis();
//                String time = String.valueOf((timeStamp / 1000 + 7200));
//                //            int insertId= pubUserDao.insertAccessToken(accessToken,time,expires_in);
//                System.out.println("accessToken的值为：" + accessToken);
//            } else {
//                log.info("获取公众号 accessToken 失败， {}", jsonResult.toJSONString());
//            }
//        } else {
//            log.info("获取公众号 accessToken 失败， {}", jsonResult.toJSONString());
//        }
//        return accessToken;
//    }
//
//
//    //拉取公众号openid,然后根据openid获取公众号unionid
//    //获取api:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140839
//    public Object getUserOpenIdList(String nextOpenid, String accessToken) throws Exception {
//        //用户openid列表信息
//        synchronized (this) {
//            try {
//                //查询是否有accessToken（我存在了数据库了，所以从数据库里查了
////                List<Map<String, Object>> accessTokenList = pubUserDao.queryAccessToken();
////                accessToken = String.valueOf(accessTokenList.get(0).get("pro_act_code"));
////                do {
//                //微信公众号获取用户列表信息接口地址
//                String requestUrl = null;
//                if (StringUtils.isBlank(nextOpenid)) {
//                    requestUrl = new StringBuffer().append("https://api.weixin.qq.com/cgi-bin/user/get?access_token=").append(accessToken).toString();
//                } else {
//                    requestUrl = new StringBuffer().append("https://api.weixin.qq.com/cgi-bin/user/get?access_token=")
//                            .append(accessToken).append("&next_openid=").append(nextOpenid).toString();
//                }
//                //后台请求
//                ResponeVo responeVo = HttpUtils.get(requestUrl);
//                JSONObject jsonResult = JSONObject.parseObject(responeVo.getContent());
//                System.out.println("openIdListInfo的值为：" + jsonResult);
//                if (jsonResult != null) {
//                    //获取用户openid列表对象
//                    JSONObject wxOpenidInfo = (JSONObject) jsonResult.get("data");
//                    System.out.println("wxOpenidInfo的值为：" + wxOpenidInfo);
//                    if (wxOpenidInfo != null) {
//                        JSONArray openids = wxOpenidInfo.getJSONArray("openId");
//                        if (openids != null && openids.size() > 0) {
//                            //获取openid和unionid
//                            List<Map<String, Object>> userInfoList = new ArrayList<>();
//                            List<JSONObject> user_list = new ArrayList<>();
////                                for (JSONArray openid : openids) {
////                                    JSONObject map = new JSONObject();
////                                    map.put("openid", openid);
////                                    map.put("lang", "zh_CN");
////                                    user_list.add(map);
////                                }
//                            JSONObject jo = new JSONObject();
//                            jo.put("user_list", user_list);
//
//                            //插入数据库
//                        }
//
//                    }
//
//                } else {
//                    return null;
//                }
////                }
////                while (openIdListInfo.getCount() == 10000);
//            } catch (Exception e) {
//                //LOG.error("获取用户列表失败",e);
//                e.printStackTrace();
//                return null;
//            }
//        }
//        return null;
//    }
//
//    public String getPublicUnionIdByOpenId(String accessToken) {
//        String openids = "omzjg008s69DX1OkOscvEazvscnI,omzjg03f9F0wTewREj29U-1vKB-Q,omzjg00gP_NIBJlNhNAynDRNmAKQ,omzjg01o6y1ItGpHDy5JxhzlV-qM,omzjg0xBN2y9dzuVQf6m2dX7L-pM,omzjg04atJ3plc9AU6GfrWftAT7c,omzjg03uyPkKo3ABoJdSl8PqzGXM,omzjg04_ugqC_-n1YmyB3DIoE_B0,omzjg08kqou0eZDs4Z6p_bO3I-Hw,omzjg07GunX4F-ymiBcWxXi1kT7g,omzjg00dSZ7_JeKZ7I4m8a-QnkR8,omzjg06u1iZ4TJ-KbAvH2XvwtdZk,omzjg0-oOSHlFUyhnXNHzvMgRB7U,omzjg06Yw_k6t2EbdrgD5kg5SiaA,omzjg08HlMnzyONDgrXU2mOLLdls,omzjg0zuP4hXm8KtiPHbLrM5hSKE,omzjg091ZinwzwL6dPOH9qwisDaM,omzjg0y3gmWDm5kHg5vsvZAgyff0,omzjg08qR46-lxXyNJ_tes5-du9g,omzjg054yQVy1tk6MHUPxqLy_l9o,omzjg0051DrxndMr0aQBatLdB9ao,omzjg0_f1BmHeJoaMy9pwlDXMx6Y,omzjg05GT-njtuukgFdhch56A6TM,omzjg09s0JiMhqHpEdi-qcsOgq-c,omzjg05bvRFiJc3OboLf2e_bMncE,omzjg07Ef29x4c9i1qp-pduj0vT0,omzjg08RLL2IAbVAwwXSmi2LuSXM,omzjg0_ld23Oiku8n-_hHg0oCWlg,omzjg05W2hqIQ0YN_z8DRLH9bHfw,omzjg03TuseH9mbGOK5SLj9vEhJs,omzjg09ddB5S-FdOQeCtlcIya2bE,omzjg02qGeK1pss8S8b7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,omzjg09b6TDBxxFKYnE6N2ThASBc,omzjg0wymphY_jp3WMV9vsH2g_Ns,omzjg0yXuuC19GgiVFRcF8mmiu2Y,omzjg01mp13KS2x-vp9or1H8SX4Y,omzjg0xPmWfHRBUxxsHiY9i0HCuY,omzjg07Gnl2bbsBRx_Q5jcUXKAWg,omzjg06nm9uONrbRPBoZ92H5LdLw,omzjg078k9aPKDdFuM3sX7ja3-c4,omzjg01e32Ho4X8BWE-qRCX4-5XI,omzjg0zLGE2i1ynV_VY9aV6X6sFw,omzjg010qmIxcFEFDMrsLEw0EXn8,omzjg02ZQQlUDFnY7h_NQ1u8Rj1s,omzjg0xPKvVJ_UoZKOTHjSfCU4hk";
//        String[] split = openids.split(",");
//        try {
//            List<JSONObject> user_list1 = new ArrayList<>();
//            List<JSONObject> user_list2 = new ArrayList<>();
//            int i = 0;
//            for (String openid : split) {
//                JSONObject map = new JSONObject();
//                map.put("openid", openid);
//                map.put("lang", "zh_CN");
//                if (i > 90) {
//                    user_list2.add(map);
//                } else {
//                    user_list1.add(map);
//                }
//                i++;
//            }
//            JSONObject json = new JSONObject();
//            for (int k = 0; k < 2; k++) {
//                //根据公众号openid获取公众号unionid
//                String requestUrl2 = null;
//                requestUrl2 = new StringBuffer().append("https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=").append(accessToken).toString();
//                //json转换成map
//                if (k == 0) {
//                    json.put("user_list", user_list1);
//                } else {
//                    json.put("user_list", user_list2);
//                }
//                ResponeVo responeVoStr = HttpUtils.post(requestUrl2, json.toJSONString());
//                JSONObject strArr = JSONObject.parseObject(responeVoStr.getContent());
//                List<JSONObject> userInfoList = (List<JSONObject>) strArr.get("user_info_list");
//                if (userInfoList.size() > 0) {
//                    for (JSONObject objectMap : userInfoList) {
//                        System.out.println("****:" + objectMap.toJSONString());
//                        String unionid = objectMap.getString("unionid");
//                        String openid = objectMap.getString("openid");
//                        if ("oqtVx5m-9T1EtMsxD1aespXzN-U8".equals(unionid)) {
//                            System.out.println("openid>>>>>>>>>>>>>" + openid);
//                        }
//                    }
//                }
//            }
//        } catch (Exception e) {
//            log.info(e.getMessage());
//        }
//        return "";
//    }
//
//    @RequestMapping("sendMsg")
//    public void sendMessage() throws Exception {
//
////        List<Map<String, Object>> accessTokenList = new ArrayList<>();
////        accessTokenList = pubUserDao.queryAccessToken();
////        String accessToken = String.valueOf(accessTokenList.get(0).get("pro_act_code"));
//        String accessToken = "47_HCgH5O9PmylM_Ajgo1-_ujZ4lRGZ53IAY7y2yiVj1F87aualC-pBIczyVfEjZ39uFek2T5O8W4UesOtiPZumkEltAdXMWCpFLAlTJnGSpjhzsRv5CWUjEptTHOpjHn_yUXyBNmquKJVPJ0y-STPjABAABX";
//        String tmpurl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
//
//        JSONObject json = new JSONObject();
//
//        //所要发送的用户 公众号的 openId
//        json.put("touser", "omzjg09wxUbgL-aNFaixj4YYr45M");
//        json.put("template_id", "JTOesm5DePJhUGYipKMC50GWhRInRg5yTzaofDDdKWg");
//        json.put("page", "view/home/Home");//点击模板可以跳转到小程序的具体界面
//        //json.put("form_id", formId);//用户的fromId或者预订单Id
//
//        // 配置小程序信息
//        JSONObject jo = new JSONObject();
//        jo.put("appid", appId); // 小程序APPID
//        jo.put("pagepath", "view/home/Home");
//        json.put("miniprogram", jo);
//        json.put("topcolor", "#173177");
//
//        // 模板内容信息
//        JSONObject data = new JSONObject();
//
//        JSONObject first = new JSONObject();
//        first.put("value", "测试");
//        first.put("color", "#173177");
//        data.put("first", first);
//
//        JSONObject keyword1 = new JSONObject();
//        keyword1.put("value", "测试主题");
//        keyword1.put("color", "#173177");
//        data.put("keyword1", keyword1);
//
//        JSONObject keyword2 = new JSONObject();
//        keyword2.put("value", "事项描述:测试施工");
//        keyword2.put("color", "#173177");
//        data.put("keyword2", keyword2);
//
//        JSONObject remark = new JSONObject();
//        remark.put("value", "备注说明刻刻");
//        remark.put("color", "#173177");
//        data.put("remark", remark);
//
//        json.put("data", data);//这个data可以直接调用上文的JsonMsg方法生成所需要发送给用户的信息
//
//        ResponeVo post = HttpUtils.post(tmpurl, json.toJSONString());
//        log.info("微信数据:" + post.getContent());
//        HttpUtils.get(tmpurl); //注意推送需要是get模式
//        JSONObject resultJson = JSONObject.parseObject(post.getContent());
//        System.out.println("模板消息返回数据:" + resultJson);
//        String errmsg = (String) resultJson.get("errmsg");
//        if (!"ok".equals(errmsg)) {  //如果为errmsg为ok，则代表发送成功，公众号推送信息给用户了。
//            System.out.println("send success");
//        } else {
//            System.out.println("send fail");
//        }
//
////        for(int i=0;i<infoList.size();i++){ //循环推送
////            json.put("touser", infoList.get(i).get("openid"));//所要发送的用户openId
////            json.put("template_id", "模板id");
////            json.put("page", "pages/index/index");//点击模板可以跳转到小程序的具体界面
////            //json.put("form_id", formId);//用户的fromId或者预订单Id
////            JSONObject jo = new JSONObject();
////            jo.put("appid","公众号appid");
////            jo.put("pagepath", "pages/me/me");
////            json.put("miniprogram", jo);
////            json.put("topcolor", "#173177");
////            json.put("data", JsonMsg(infoList.get(i)));//这个data可以直接调用上文的JsonMsg方法生成所需要发送给用户的信息
////            // json.toString()
////            String result = HttpUtils.get(tmpurl); //注意推送需要是get模式
////            JSONObject resultJson = JSON.parseObject(result);
////            System.out.println("模板消息返回数据:"+resultJson);
////            String errmsg = (String) resultJson.get("errmsg");
////            if(!"ok".equals(errmsg)){  //如果为errmsg为ok，则代表发送成功，公众号推送信息给用户了。
////                System.out.println("send success");
////            } else{
////                System.out.println("send fail");
////            }
////        }
//    }
//
//
//    /**
//     * 消息推送
//     * https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html
//     *
//     * @return
//     */
//    @RequestMapping(value = "/subscribeMessage", method = RequestMethod.POST)
//    @ApiOperation(httpMethod = "POST", value = "消息推送", notes = "消息推送")
//    public Object subscribeMessage(@RequestBody WxMssDto wxMssDto)
//            throws IOException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
//        String res = buildMessageUrlToPost(wxMssDto);
//        JSONObject jsonObject = JSONObject.parseObject(res);
//        int errcode = jsonObject.getIntValue("errcode");
//        switch (errcode) {
//            case 40003:
//                throw new BaseException("touser字段openid为空或者不正确");
//            case 40037:
//                throw new BaseException("订阅模板id为空不正确");
//            case 43101:
//                throw new BaseException("用户拒绝接受消息，如果用户之前曾经订阅过，则表示用户取消了订阅关系");
//            case 47003:
//                throw new BaseException("模板参数不准确，可能为空或者不满足规则，errmsg会提示具体是哪个字段出错");
//            case 41030:
//                throw new BaseException("page路径不正确，需要保证在现网版本小程序中存在，与app.json保持一致");
//            default:
//                break;
//        }
//        return true;
//    }
//
//    /**
//     * 技术库文档二维码
//     *
//     * @return
//     */
//    @RequestMapping(value = "/getQrCode", method = RequestMethod.GET)
//    @ApiOperation(httpMethod = "GET", value = "技术库文档二维码", notes = "技术库文档二维码")
//    public void getQrCode(String scene, Long width,
//                          @RequestParam(value = "fileType", required = false, defaultValue = "png") String fileType,
//                          HttpServletResponse response) {
//        String token = smallProService.getSmallProToken();
//        String page = "view/home/infoQuery/technologyQuery/TechnologyDetail";
//        smallProService.getSmallProQrCodeResponse(token, scene, page, Long.valueOf(width), null, null, null, response,
//                "技术库文档", fileType);
//    }
//
//    private String buildMessageUrlToPost(WxMssDto wxMssDto)
//            throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, IOException {
//        String token = smallProService.getSmallProToken();
//        String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + token;
//        // 处理模板数据
//        Map dataMap = JSONObject.parseObject(wxMssDto.getData());
//        JSONObject param = new JSONObject();
//        param.put("touser", wxMssDto.getTouser());
//        param.put("template_id", wxMssDto.getTemplate_id());
//        param.put("page", wxMssDto.getPage());
//        param.put("data", dataMap);
//        ResponeVo post = HttpUtils.post(url, param.toJSONString());
//        log.info("微信数据:" + post.getContent());
//        String status = "发送失败";
//        String failMessage = "";
//        JSONObject jsonObject = JSONObject.parseObject(post.getContent());
//        int errcode = jsonObject.getIntValue("errcode");
//        switch (errcode) {
//            case 40003:
//                failMessage = "touser字段openid为空或者不正确";
//                break;
//            case 40037:
//                failMessage = "订阅模板id为空不正确";
//                break;
//            case 43101:
//                failMessage = "用户拒绝接受消息，如果用户之前曾经订阅过，则表示用户取消了订阅关系";
//                break;
//            case 47003:
//                failMessage = "模板参数不准确，可能为空或者不满足规则，errmsg会提示具体是哪个字段出错";
//                break;
//            case 41030:
//                failMessage = "page路径不正确，需要保证在现网版本小程序中存在，与app.json保持一致";
//            default:
//                status = "发送成功";
//                break;
//        }
//        WechatSendMessage wechatSendMessage = new WechatSendMessage();
//        wechatSendMessage.setOpenId(wxMssDto.getTouser());
//        wechatSendMessage.setMessage(param.toJSONString());
//        wechatSendMessage.setStatus(status);
//        wechatSendMessage.setTemplateId(wxMssDto.getTemplate_id());
//        wechatSendMessage.setFailMessage(failMessage);
//        wechatSendMessage.setResult(post.getContent());
//        wechatSendMessage.setCreateDate(new Date());
//        wechatSendMessageService.save(wechatSendMessage);
//        return post.getContent();
//    }
//
//    private String buildOpenIdUrl(String appId, String secret, String code) {
//        String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + appId + "&secret=" + secret + "&js_code="
//                + code + "&grant_type=authorization_code";
//        return url;
//    }
//
//    /**
//     * 技术库文档二维码
//     *
//     * @return
//     */
//    @RequestMapping(value = "/getTutorial", method = RequestMethod.GET)
//    @ApiOperation(httpMethod = "GET", value = "获取使用指南文档id", notes = "获取使用指南文档id")
//    public String getTutorial() {
//        return tutorialId;
//    }
//
//
//    @RequestMapping(value = "/test/send/message", method = RequestMethod.GET)
//    @ApiOperation(httpMethod = "GET", value = "测试微信消息通知", notes = "测试微信消息通知")
//    public void testSendMessage(@RequestParam("messageData") String messageData) throws Exception {
//        List<String> openIds = new ArrayList<>();
//        if (StringUtil.isNotEmpty(messageData)) {
//            openIds.add("ocN2g4nkM4KOIKC6rdLKs-1Tt-Rc");
//            String template = "2";
//            List<String> message = new ArrayList<>();
//            String[] split = messageData.split("#");
//            for (String s : split) {
//                message.add(s);
//            }
//            smallProService.sendWeChatUpcomingMessage(openIds, template, message);
//        }
//    }
//}
